package com.zjk.storage.core;

import com.zjk.storage.core.exception.FileStorageException;
import com.zjk.storage.core.provider.FileStorage;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class FileStorageFactory {
    private final Map<String, FileStorage> fileStorageMap = new ConcurrentHashMap<>();

    public FileStorage getFileStorage(String platform) {
        return Optional.ofNullable(fileStorageMap.get(platform)).orElseThrow(() -> new RuntimeException("未找到对应的文件存储平台"));
    }

    public void addFileStorage(String platform, FileStorage fileStorage) {
        if (fileStorageMap.containsKey(platform)) {
            throw new FileStorageException("文件存储平台已存在");
        }
        fileStorageMap.put(platform, fileStorage);
    }
}
